package com.ruoyi;

import com.ruoyi.common.utils.sqlite.Jdbc;
import com.ruoyi.common.utils.sqlite.JdbcFactory;
import com.ruoyi.common.utils.sqlite.SqlParameter;
import com.ruoyi.project.wenyanwen.generate.convert.AbstractConvert;
import jodd.io.ZipUtil;

import java.util.List;

class Voice {
    private int id;
    private String pinyin;
    private byte[] data;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getPinyin() {
        return pinyin;
    }

    public void setPinyin(String pinyin) {
        this.pinyin = pinyin;
    }

    public byte[] getData() {
        return data;
    }

    public void setData(byte[] data) {
        this.data = data;
    }
}

class Zyzx {
    private int id;

    private byte[] image;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public byte[] getImage() {
        return image;
    }

    public void setImage(byte[] image) {
        this.image = image;
    }
}

public class Test {

    public static void main(String[] args) throws Exception {

        Class.forName("org.sqlite.JDBC");

        //ZipUtil.zip("/home/jacky/Downloads/zyzx2.db");

        Jdbc jdbc = JdbcFactory.getJdbc("/home/jacky/Downloads/zyzx2.db");
        jdbc.setAutoCommit(false);

        List<Zyzx> zyzxes = jdbc.getList("SELECT _id as id, image FROM zyzx", Zyzx.class, new SqlParameter());
        for (Zyzx zyzx : zyzxes) {
            System.out.println(zyzx.getId());
            byte[] data = zyzx.getImage();
            System.out.println(data.length);
//            byte[] zipData = AbstractConvert.zip(data);
//            System.out.println(data.length + " -> " + zipData.length);
//            SqlParameter param = new SqlParameter();
//            param.setBytes(zipData);
//            param.setInt(zyzx.getId());
//            jdbc.execute("update zyzx set image = ? where _id = ?", param);
        }
        jdbc.commit();
    }

}
